package com.share.all.config;

import org.springframework.cache.interceptor.KeyGenerator;

import java.lang.reflect.Method;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author caifan
 * @since 2023/2/3
 */
public class CustomKeyGenerator implements KeyGenerator {
    @Override
    public Object generate(Object target, Method method, Object... params) {
        return target.getClass().getSimpleName() + "_"
                + method.getName() + (params.length > 0 ? "_" : "")
                + Stream.of(params).filter(Objects::nonNull).map(Object::toString).collect(Collectors.joining("_"));
    }
}
